<template>
	<div :style="{
    margin:'20px'
  }">
      <el-row>
        <el-col :span="8">参数</el-col>
        <el-col :span="16">备注</el-col>
      </el-row>
      <el-checkbox-group
        v-model="checkedList">
        <el-row v-for="(item,index) in columns" :key="index">
          <el-col :span="8"><el-checkbox :label="item.paramId">{{item.paramName}}</el-checkbox></el-col>
          <el-col :span="16" style="font-size: 14px;">{{item.remark}}</el-col>
        </el-row>
      </el-checkbox-group>
      <div class="upWard">
        <el-button size="small" type="primary" @click="saveHandle">保存</el-button>
      </div>
	</div>
</template>

<script>
// import { dictionary } from '@/utils/dictMixin';
import { queryAll, updateSystemParam } from '@/api/retail/basedata/definition';
import { notifyAction } from '@/utils';
export default {
	name: 'confirmcar',
	// mixins: [dictionary],
	components: {
	},
	data() {
		return {
      columns: [],
      fetchApi: '',
      fetchParams: {},
      formData: {},
      checkedList: [],
      defineObj: {
        '10131001' : true // 被选中
      },
      userInfo: ''
		}
	},
	methods: {
    async init(){
      let { defineObj } = this
      this.checkedList = [];
      await queryAll().then(res => {
        this.columns = res.data;
        this.columns.forEach(item => {
          defineObj[item['paramValue']] ? this.checkedList.push(item.paramId) : '';
          // item['value'] = defineObj[item['paramValue']] || false;
        });
      })
    },
		createFormList() {
      return [];
    },
    createTableColumns (){
      return [
        {
          paramId: '',
          paramType: '',
          recordVersion: '',
          paramName: '是否需要销售经理审核',
          paramValue: '', // 10131001
          remark:'客户订单审核，选中需要销售经理审核，不选中则不需要销售经理审核'
        }, {
          paramId: '',
          paramType: '',
          recordVersion: '',
          paramName: '是否需要财务审核',
          paramValue: '',
          remark: '客户订单财务审核，选中需要财务审核，不选中则不需要财务审核'
        }
      ]
    },
    saveHandle (){ // 保存事件: 暂无接口
      let { columns, checkedList, userInfo } = this
      let systemParam = columns.map(item => {
        if(checkedList && checkedList.length > 0 && checkedList.includes(item.paramId) ){
          item.paramValue = 10131001
        } else {
          item.paramValue = null
        }
        let paramId = item.paramId
        let paramValue = item.paramValue
        let recordVersion = item.recordVersion
        return { paramId, paramValue, recordVersion }
      })
      updateSystemParam(systemParam).then(res => {
        console.log('res', res)
        if (res.resultCode === 200 && res.success) {
          notifyAction('修改成功');
          this.init()
        } else {
          notifyAction(res.errMsg, 'error');
        }
      })
    }
  },
  mounted () {
    this.init()
  }
}
</script>

<style scoped="scoped" lang="less">
  .el-row{
    padding: 10px 0;
    margin-bottom: 20px;
    &:last-child {
      margin-bottom: 0;
    }
  }
  .upWard{
    position: absolute;
    bottom: 0;
    left: 50%;
    margin-bottom: 120px;
  }
</style>
